<script>
	import { getLocation, getSystemInfo, reverseGeocode, mergeUrls, moveToLocation, getUserInfo, timesFormat} from '@/util/util.js';
	import { UploadGps } from '@/util/UploadGps.js';
	import { AutoUpdate } from '@/util/AutoUpdate.js';
	import { Push } from '@/util/push.js';

	export default {
		data() {
			return {
				uploadGps: null,
				autoUpdate: null
			}
		},
		methods: {},
		async onLaunch() {
			// #ifdef APP-VUE || APP-NVUE
			
			uni.setKeepScreenOn({
				keepScreenOn: true
			});
			
			let {
				platform
			} = await getSystemInfo();

			if (platform == 'android') {
				this.autoUpdate = new AutoUpdate();
				this.autoUpdate.cycle();
			}

			// #endif

			this.uploadGps = new UploadGps();

			uni.$on('uploadGps.check', () => {
				this.uploadGps.check().then(() => {
					this.uploadGps.cycle();
				}, () => {
					this.uploadGps.pause();
				})
			});


			let push = new Push({
				fn: (pushId) => {
					this.$store.dispatch({
						type: 'push/setPushId',
						pushId
					});
				}
			});

			push.cycle();

			push.bindEvent();

			if (plus.runtime.appid !== 'HBuilder') { // 真机运行不需要检查更新，真机运行时appid固定为'HBuilder'，这是调试基座的appid
				uni.request({
					url: 'https://7a3e3fa9-7820-41d0-be80-11927ac2026c.bspapp.com/http/update', //检查更新的服务器地址
					data: {
						appid: plus.runtime.appid,
						version: plus.runtime.version,
						imei: plus.device.imei
					},
					success: (res) => {
						if (res.statusCode == 200 && res.data.isUpdate) {
							// 提醒用户更新
							uni.showModal({
								title: '更新提示',
								content: res.data.note ? res.data.note : '是否选择更新',
								success: (ee) => {
									if (ee.confirm) {
										plus.runtime.openURL(res.data.url);
									}
								}
							})
						}
					}
				})
			}
		},
		onShow() {
			this.uploadGps = new UploadGps();

			this.uploadGps.check().then(() => {
				this.uploadGps.cycle();
			}, () => {
				this.uploadGps.pause();
			})
		},
		onHide() {}
	}
</script>

<style>
	/*每个页面公共css */
	// #ifndef APP-NVUE
	@import './common/uni.css';
	// #endif
</style>
